import { DynamicModule, Module } from '@nestjs/common';
import { AmqpClientService } from './amqp-client.service';
import { ConnectOptions } from './type/ConnectOptions';


@Module({
	providers: [AmqpClientService],
	exports: [AmqpClientService],
})
export class AmqpClientModule {

	static forRootAsync(connections: {
		imports?: any[]; // 需要导入的模块
		useFactory: (...args: any[]) => Promise<ConnectOptions> | ConnectOptions;
		inject?: any[]; // 工厂函数的依赖项
	  }): DynamicModule {
		return {
			module: AmqpClientModule,
			imports: connections.imports || [], // 导入其他模块
			providers: [
				{
					provide: 'AMQP_CONNECT_OPTIONS',
					useFactory: connections.useFactory,
					inject: connections.inject || [],
				},
				AmqpClientService,
			],
			exports: [AmqpClientService],
		};
	  }











	// static forRootAsync1(options: {
	// 	imports?: any[];
	// 	useFactory: (...args: any[]) => Promise<ConnectOptions> | ConnectOptions;
	// 	inject?: any[];
	//   }): DynamicModule {
	// 	const providers = [
	// 	  {
	// 		provide: 'AMQP_CONNECT_OPTIONS',
	// 		useFactory: options.useFactory,
	// 		inject: options.inject || [],
	// 		imports : options.imports
	// 	  },
	// 	  AmqpClientService,
	// 	];
	
	// 	return {
	// 	  module: AmqpClientModule,
	// 	  providers: providers,
	// 	  exports: [AmqpClientService],
	// 	};
	// }
}
